package com.bw.server.server

import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.bw.server.R
import com.bw.server.entity.ServiceEntity
import com.bw.server.entity.ServiceEntityItem
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

class ServiceAdapter:BaseQuickAdapter<ServiceEntity,BaseViewHolder>(R.layout.item_one) {
    override fun convert(holder: BaseViewHolder, item: ServiceEntity) {
        //一级列表
        holder.getView<TextView>(R.id.tv_one).text = item.title

        val adapter = ServiceItemAdapter()
        //二级列表
        holder.getView<RecyclerView>(R.id.item_rv).adapter  = adapter
        adapter.setList(item.itemData)


        adapter.setOnItemClickListener { adapter, view, position ->

             if (item.title == "为你推荐"){
                 when(item.itemData[position].id){
                     1->{}
                     2->{}
                     3->{}
                     4->{}
                     5->{}
                 }
             }else if (item.title == "物业服务"){
                 when(item.itemData[position].id){
                     1->{}
                     2->{}
                     3->{}
                     4->{}
                     5->{}
                     6->{}
                     7->{}
                 }
             } else if (item.title == "企业服务"){
                 when(item.itemData[position].id){
                     1->{}
                     2->{}
                     3->{}
                     4->{}
                     5->{}
                 }
             } else if (item.title == "人才关爱"){
                 when(item.itemData[position].id){
                     1->{}
                     2->{}
                     3->{}
                 }
             } else if (item.title == "外包服务"){
                 when(item.itemData[position].id){
                     1->{}
                 }
             }else if (item.title == "基础服务"){
                 when(item.itemData[position].id){
                     1->{
                         //跳转到设备管理页面
                   ARouter.getInstance().build("/server/DeviceActivity").navigation()
                    //startActivity(Intent(context, DeviceActivity::class.java))
                    ToastUtils.showLong(item.itemData[position].id)
                     }
                     2->{}
                 }
             }
        }

    }
}


class ServiceItemAdapter: BaseQuickAdapter<ServiceEntityItem,BaseViewHolder>(R.layout.item_server) {
    override fun convert(holder: BaseViewHolder, item: ServiceEntityItem) {
        holder.setText(R.id.tv_title,item.title)
        val view = holder.getView<ImageView>(R.id.iv_icon)
        view.setImageResource(item.image)


    }

}
